/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package calculadora;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author colombo
 */
public class Calculadora {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        inal int suma = 1;
    final int resta = 2;
    final int multiplicacion = 3;
    final int dividir = 4;
    private List <Integer> valores = new ArrayList<Integer>();
    private int resultado = 0;
    private int operacion = 0;
    private String valor = "";
    public Calculadora () {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jBNumer1 = new javax.swing.JButton();
        jBNumer2 = new javax.swing.JButton();
        jBNumer3 = new javax.swing.JButton();
        jBNumer6 = new javax.swing.JButton();
        jBNumer4 = new javax.swing.JButton();
        jBNumer5 = new javax.swing.JButton();
        jBNumer8 = new javax.swing.JButton();
        jBNumer9 = new javax.swing.JButton();
        jBNumer7 = new javax.swing.JButton();
        jBIgual = new javax.swing.JButton();
        jBNumer0 = new javax.swing.JButton();
        jBMenos = new javax.swing.JButton();
        jBMas = new javax.swing.JButton();
        jBDividir = new javax.swing.JButton();
        jBMultiplicar = new javax.swing.JButton();
        jTDisplay = new javax.swing.JTextField();
        jBMemoria = new javax.swing.JButton();
        jBApagar = new javax.swing.JButton();
        jTRegresar = new javax.swing.JToggleButton();
        jTNueva = new javax.swing.JToggleButton();
        jTSalir = new javax.swing.JToggleButton();
        jLElectronic = new javax.swing.JLabel();

        jLabel1.setText("jLabel1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jBNumer1.setText("1");
        jBNumer1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNumer1ActionPerformed(evt);
            }
        });

        jBNumer2.setText("2");
        jBNumer2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNumer2ActionPerformed(evt);
            }
        });

        jBNumer3.setText("3");
        jBNumer3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNumer3ActionPerformed(evt);
            }
        });

        jBNumer6.setText("6");
        jBNumer6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNumer6ActionPerformed(evt);
            }
        });

        jBNumer4.setText("4");
        jBNumer4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNumer4ActionPerformed(evt);
            }
        });

        jBNumer5.setText("5");
        jBNumer5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNumer5ActionPerformed(evt);
            }
        });

        jBNumer8.setText("8");
        jBNumer8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNumer8ActionPerformed(evt);
            }
        });

        jBNumer9.setText("9");
        jBNumer9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNumer9ActionPerformed(evt);
            }
        });

        jBNumer7.setText("7");
        jBNumer7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNumer7ActionPerformed(evt);
            }
        });

        jBIgual.setText("=");
        jBIgual.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBIgualActionPerformed(evt);
            }
        });

        jBNumer0.setText("0");
        jBNumer0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNumer0ActionPerformed(evt);
            }
        });

        jBMenos.setText("-");
        jBMenos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBMenosActionPerformed(evt);
            }
        });

        jBMas.setText("+");
        jBMas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBMasActionPerformed(evt);
            }
        });

        jBDividir.setText("/");
        jBDividir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBDividirActionPerformed(evt);
            }
        });

        jBMultiplicar.setText("*");
        jBMultiplicar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBMultiplicarActionPerformed(evt);
            }
        });

        jTDisplay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTDisplayActionPerformed(evt);
            }
        });

        jBMemoria.setText("MR");
        jBMemoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBMemoriaActionPerformed(evt);
            }
        });

        jBApagar.setText("ON");

        jTRegresar.setText("Regresar");
        jTRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTRegresarActionPerformed(evt);
            }
        });

        jTNueva.setText(" Nueva consulta ");
        jTNueva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTNuevaActionPerformed(evt);
            }
        });

        jTSalir.setText("Salir");
        jTSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTSalirActionPerformed(evt);
            }
        });

        jLElectronic.setForeground(new java.awt.Color(102, 102, 102));
        jLElectronic.setText("CALCULADORA WILLIAM");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTDisplay)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jBNumer7)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jBNumer8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jBNumer9))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jBNumer0)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jBIgual)
                                        .addGap(4, 4, 4)
                                        .addComponent(jTNueva, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addComponent(jBNumer1)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jBNumer2, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(jBNumer3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addComponent(jBNumer4)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(jBNumer5)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jBNumer6))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jBMemoria)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jBApagar))
                                        .addGroup(layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jBMas)
                                                .addComponent(jBMultiplicar))
                                            .addGap(36, 36, 36)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jBDividir)
                                                .addComponent(jBMenos))))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jTRegresar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(38, 38, 38))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLElectronic, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLElectronic, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19)
                .addComponent(jTDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBNumer1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBNumer2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBNumer3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBMas, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBMenos, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBNumer4, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBNumer5, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBNumer6, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBDividir, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBMultiplicar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBNumer7, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBNumer8, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBNumer9, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBMemoria, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBApagar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTSalir, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jBNumer0, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jBIgual, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTNueva, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void jBNumer5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        valor += "5";
        jTDisplay.setText(valor);
    }                                        

    private void jBNumer7ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
         valor += "7";
        jTDisplay.setText(valor);
    }                                        

    private void jBIgualActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        ejecutarOperacion();
        operacion = 0;
        
        
    }                                       

    private void jBNumer0ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
         valor += "0";
        jTDisplay.setText(valor);
    }                                        

    private void jBNumer1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            // TODO add your handling code here:
        valor += "1";
        jTDisplay.setText(valor);
    }                                        

    private void jBNumer3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        valor += "3";
        jTDisplay.setText(valor);
    }                                        

    private void jBNumer2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        valor += "2";
        jTDisplay.setText(valor);
    }                                        

    private void jBNumer4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
         valor += "4";
        jTDisplay.setText(valor);
    }                                        

    private void jBNumer6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        valor += "6";
        jTDisplay.setText(valor);
    }                                        

    private void jBNumer9ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        valor += "9";
        jTDisplay.setText(valor);
    }                                        

    private void jBMenosActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        ejecutarOperacion();
        operacion = resta;
    }                                       

    private void jBDividirActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        ejecutarOperacion();
        operacion = dividir;
    }                                         

    private void jBMemoriaActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
    }                                         

    private void jTNuevaActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        operacion = 0;
        jTDisplay.setText("0");
      
    }                                       

    private void jTRegresarActionPerformed(java.awt.event.ActionEvent evt) {                                           
       Login lon = new Login ();
       lon.main (new String [1]);
       this.setVisible(false);
    }                                          

    private void jTSalirActionPerformed(java.awt.event.ActionEvent evt) {                                        
        System.exit(0);
    }                                       

    private void jTDisplayActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
    }                                         

    private void jBMasActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
        ejecutarOperacion();
        operacion = suma;
    }                                     

    private void jBNumer8ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
         valor += "8";
        jTDisplay.setText(valor);
    }                                        

    private void jBMultiplicarActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
        ejecutarOperacion();
        operacion = multiplicacion;
    }                                             

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Calculadora.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Calculadora.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Calculadora.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Calculadora.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Calculadora().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jBApagar;
    private javax.swing.JButton jBDividir;
    private javax.swing.JButton jBIgual;
    private javax.swing.JButton jBMas;
    private javax.swing.JButton jBMemoria;
    private javax.swing.JButton jBMenos;
    private javax.swing.JButton jBMultiplicar;
    private javax.swing.JButton jBNumer0;
    private javax.swing.JButton jBNumer1;
    private javax.swing.JButton jBNumer2;
    private javax.swing.JButton jBNumer3;
    private javax.swing.JButton jBNumer4;
    private javax.swing.JButton jBNumer5;
    private javax.swing.JButton jBNumer6;
    private javax.swing.JButton jBNumer7;
    private javax.swing.JButton jBNumer8;
    private javax.swing.JButton jBNumer9;
    private javax.swing.JLabel jLElectronic;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTDisplay;
    private javax.swing.JToggleButton jTNueva;
    private javax.swing.JToggleButton jTRegresar;
    private javax.swing.JToggleButton jTSalir;
    // End of variables declaration                   

    private void ejecutarOperacion() {
        
        switch(operacion){
            
            case 0 :{ resultado = Integer.parseInt(jTDisplay.getText());}break;
            case suma : {resultado = resultado + Integer.parseInt(jTDisplay.getText());} break;
                case resta : {resultado = resultado - Integer.parseInt(jTDisplay.getText());} break;
                    case multiplicacion : {resultado = resultado * Integer.parseInt(jTDisplay.getText());} break;
                        case dividir : {resultado = resultado / Integer.parseInt(jTDisplay.getText());} break;
                
        }
        
        jTDisplay.setText(""+resultado);
        valor = "";
    }
 
}
    
}
        
        
}
}
}